package com.example.pet.config.interceptor;

import com.example.pet.util.SessionUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        Object user = SessionUtil.getUser();
        if (user != null){
            return true;
        }else {
            response.sendRedirect("/login");
            return false;
        }
    }

}
